﻿using Microsoft.AspNetCore.Builder;
using Serilog;

namespace ZeroSum.Extend.Logging.Serilog;

public static class SerilogHostingExtension
{
    public static WebApplicationBuilder UseSerilogDefault(this WebApplicationBuilder builder,
        Action<LoggerConfiguration>? configAction = default)
    {
        builder.WebHost.UseSerilog((context, configuration) =>
        {
            // 加载配置文件
            var config = configuration
                .ReadFrom.Configuration(context.Configuration)
                .Enrich.FromLogContext();

            configAction?.Invoke(config);
        });

        return builder;
    }
}